
export namespace LocalStore {

    export enum Key {
        SocketURL = 'SocketURL',
        SocketSendCMDList = 'SocketSendList',
        SocketListenCMDList = 'SocketListenCMDList'
    }

    // SocketURL

    export function saveSocketURL(url: string){
        localStorage.setItem(Key.SocketURL, url)
    }
    export function getSocketURL(): string | null {
        return localStorage.getItem(Key.SocketURL)
    }
    export function clearSocketURL() {
        return localStorage.removeItem(Key.SocketURL)
    }

    // SocketSendCMDList

    export function saveSocketSendCMDList(items: string[]){
        try {
            localStorage.setItem(Key.SocketSendCMDList, JSON.stringify(items))
        }catch (e) { }
    }
    export function getSocketSendCMDList(): string[] {
        const result = localStorage.getItem(Key.SocketSendCMDList)
        if (result) {
            try {
                return JSON.parse(result) as string[]
            }catch (e) {
                return []
            }
        }
        return []
    }
    export function clearSocketSendCMDList() {
        return localStorage.removeItem(Key.SocketSendCMDList)
    }

    // SocketListenCMDList

    export function saveSocketListenCMDList(items: string[]){
        try {
            localStorage.setItem(Key.SocketListenCMDList, JSON.stringify(items))
        }catch (e) { }
    }

    export function getSocketListenCMDList(): string[] {
        const result = localStorage.getItem(Key.SocketListenCMDList)
        if (result) {
            try {
                return JSON.parse(result) as string[]
            }catch (e) {
                return []
            }
        }
        return []
    }
    export function clearSocketListenCMDList() {
        return localStorage.removeItem(Key.SocketListenCMDList)
    }

}
export default LocalStore